/* 
 * ***** BEGIN LICENSE BLOCK ***** Version: NPL 1.1/GPL 2.0/LGPL 2.1 The
 * contents of this file are subject to the Netscape Public License Version 1.1
 * (the "License"); you may not use this file except in compliance with the
 * License. You may obtain a copy of the License at http://www.mozilla.org/NPL/
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License. The
 * Original Code is lutsko.com code. The Initial Developer of the Original Code
 * is James Lutsko. Portions created by the Initial Developer are Copyright (C)
 * 2003 the Initial Developer. All Rights Reserved. Contributor(s):
 * Alternatively, the contents of this file may be used under the terms of
 * either the GNU General Public License Version 2 or later (the "GPL"), or the
 * GNU Lesser General Public License Version 2.1 or later (the "LGPL"), in which
 * case the provisions of the GPL or the LGPL are applicable instead of those
 * above. If you wish to allow use of your version of this file only under the
 * terms of either the GPL or the LGPL, and not to allow others to use your
 * version of this file under the terms of the NPL, indicate your decision by
 * deleting the provisions above and replace them with the notice and other
 * provisions required by the GPL or the LGPL. If you do not delete the
 * provisions above, a recipient may use your version of this file under the
 * terms of any one of the NPL, the GPL or the LGPL. ***** END LICENSE BLOCK
 * *****
 */

package autoteam.ui.dialogs;

import java.awt.Frame;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

public class AddTeamDialog extends JDialog
{
    
    private static final long serialVersionUID = 6349959068539027867L;
    
    String team;
    String night;
    String coach;
    
    public AddTeamDialog( Frame aFrame, String[] coaches )
    {
	super( aFrame, true );
	
	setTitle( "Add Team" );
	team = null;
	night = null;
	coach = null;
	
	final JTextField nameTextField = new JTextField( 10 );
	
	String[] nightStrings = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" };
	
	// Create the combo box
	final JComboBox nightList = new JComboBox( nightStrings );
	nightList.setSelectedIndex( 0 );
	
	final JComboBox coachList = new JComboBox( coaches );
	coachList.setSelectedIndex( 0 );
	
	Object[] array = { nameTextField, nightList, coachList };
	
	final String btnString1 = "OK";
	final String btnString2 = "Cancel";
	Object[] options = { btnString1, btnString2 };
	
	final JOptionPane optionPane; 
	optionPane = new JOptionPane( array, 
	                              JOptionPane.QUESTION_MESSAGE,
	                              JOptionPane.YES_NO_OPTION, null, 
	                              options, options[0] );
	
	optionPane.addPropertyChangeListener( new PropertyChangeListener( )
	{
	    public void propertyChange( PropertyChangeEvent e )
	    {
		String prop = e.getPropertyName( );
		
		if ( isVisible( ) && (e.getSource( ) == optionPane)
		     && (prop.equals( JOptionPane.VALUE_PROPERTY ) || 
			 prop.equals( JOptionPane.INPUT_VALUE_PROPERTY )) 
		)
		{
		    Object value = optionPane.getValue( );
		    
		    if ( value == JOptionPane.UNINITIALIZED_VALUE )
		    {
			// ignore reset
			return;
		    }
		    if ( value.equals( btnString1 ) )
		    {
			night = (String) nightList.getSelectedItem( );
			coach = (String) coachList.getSelectedItem( );
			team = (String) nameTextField.getText( );
		    }
		    setVisible( false );
		}
	    }
	} );
	
	setContentPane( optionPane );
    }
}
